var formsettings = {
  patterns : {
      email : /^[a-zA-Z0-9\.]+[@][a-zA-Z0-9\-]+([\.][a-zA-Z0-9]+)+$/,
      numeric : /^[0-9]+([\.][0-9]+)?$/,
      alphanumeric: /^[a-zA-Z0-9]+$/,
      mobilenumber: /^((\+[0-9]+)|[0][0-9]+)$/
  }
};

$(function(){
    var page_link = $('ul > li.active > a').attr('href');
    
    $(".paginate_link").click(function(event){
        event.preventDefault();
        var link = page_link+"page/"+$(this).attr('page')+'/?pagesize='+$("#pagesize").val()+'/?key='+$("#search_id").val();
        window.location = link;
    })
    
    $(".select2-choice").click(function(){
        $(this).parent().find('.select2-drop').each(function(){
            if($(this).hasClass('select2-drop-hide')){
                $(this).removeClass('select2-drop-hide');
                $(".select2-container > .select2-choice").css('border-radius','4px 4px 0 0');        
            }else{
                $(this).addClass('select2-drop-hide');
                $(".select2-container > .select2-choice").css('border-radius','4px 4px 4px 4px');     
            }
        });
    });
    
    $(".select2-results > li").click(function(){
        
        if($(this).parent().attr('mode') == 'survey'){
            $(".select2-drop").addClass('select2-drop-hide');
            $(".select2-container > .select2-choice").css('border-radius','4px 4px 4px 4px');
            
            $("#survey_category_id").val($(this).attr('num'));
            $("#span_survey_name").html($(this).html());
            
        }
        else{
            $("#pagesize").val($(this).attr('num'));
            $("#pagesize").trigger('change');
        }
    });
    
    $("#pagesize").change(function(){
        var link = page_link+"page/0/?pagesize="+$(this).val();
        window.location = link;
    })
    
    $("#search_id").live('keyup',function(e){
        if(e.keyCode == 13){
//            var keyword = $.trim($(this).val());
//            window.location = page_link+'?key='+keyword;
        }
    })
    
})


